package com.newMedical.medical.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.newMedical.common.annotation.Log;
import com.newMedical.common.core.controller.BaseController;
import com.newMedical.common.core.domain.AjaxResult;
import com.newMedical.common.enums.BusinessType;
import com.newMedical.medical.domain.DocIcd;
import com.newMedical.medical.service.IDocIcdService;
import com.newMedical.common.utils.poi.ExcelUtil;
import com.newMedical.common.core.page.TableDataInfo;

/**
 * 疾病表Controller
 * 
 * @author ruoyi
 * @date 2021-12-03
 */
@RestController
@RequestMapping("/medical/icd")
public class DocIcdController extends BaseController
{
    @Autowired
    private IDocIcdService docIcdService;

    /**
     * 查询疾病表列表
     */
    @PreAuthorize("@ss.hasPermi('medical:icd:list')")
    @GetMapping("/list")
    public TableDataInfo list(DocIcd docIcd)
    {
        startPage();
        List<DocIcd> list = docIcdService.selectDocIcdList(docIcd);
        return getDataTable(list);
    }

    /**
     * 导出疾病表列表
     */
    @PreAuthorize("@ss.hasPermi('medical:icd:export')")
    @Log(title = "疾病表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DocIcd docIcd)
    {
        List<DocIcd> list = docIcdService.selectDocIcdList(docIcd);
        ExcelUtil<DocIcd> util = new ExcelUtil<DocIcd>(DocIcd.class);
        util.exportExcel(response, list, "疾病表数据");
    }

    /**
     * 获取疾病表详细信息
     */
    @PreAuthorize("@ss.hasPermi('medical:icd:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(docIcdService.selectDocIcdById(id));
    }

    /**
     * 新增疾病表
     */
    @PreAuthorize("@ss.hasPermi('medical:icd:add')")
    @Log(title = "疾病表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocIcd docIcd)
    {
        return toAjax(docIcdService.insertDocIcd(docIcd));
    }

    /**
     * 修改疾病表
     */
    @PreAuthorize("@ss.hasPermi('medical:icd:edit')")
    @Log(title = "疾病表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocIcd docIcd)
    {
        return toAjax(docIcdService.updateDocIcd(docIcd));
    }

    /**
     * 删除疾病表
     */
    @PreAuthorize("@ss.hasPermi('medical:icd:remove')")
    @Log(title = "疾病表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(docIcdService.deleteDocIcdByIds(ids));
    }
}
